package com.car.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.car.bean.BitAutoBrand;
import com.car.json.BitAutoJSON;
import com.car.util.ConnectionPool;

public class YiCheDao {
	private Connection conn = ConnectionPool.getConnection("carvoice_core", "root", "zhouzhou100428", "192.168.1.168");

	// 插入carinfo
	public void insertCarInfo(BitAutoBrand bit) {
		PreparedStatement ps = null;
		String sql = "INSERT INTO core_brand_bitauto(bitauto_bbs,bitauto_name,bitauto_pid,bitauto_urlspell,bitauto_showname,bitauto_cssale,bitauto_goid,bitauto_goname,bitauto_rel) VALUES(?,?,?,?,?,?,?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, bit.getBitauto_bbs());
			ps.setString(2, bit.getBitauto_name());
			ps.setInt(3, bit.getBitauto_pid());
			ps.setString(4, bit.getBitauto_urlspell());
			ps.setString(5, bit.getBitauto_showname());
			ps.setInt(6, bit.getBitauto_cssale());
			ps.setInt(7, bit.getBitauto_goid());
			ps.setString(8, bit.getBitauto_goname());
			ps.setInt(9, bit.getBitauto_rel());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		YiCheDao ycd = new YiCheDao();
		BitAutoJSON baj = new BitAutoJSON();
		String url = "http://api.car.bitauto.com/CarInfo/MasterBrandToSerialNew.aspx?type=1&pid=0&rt=master&serias=m&key=master_0_1_m";
		List<String> urls = baj.getCarInfoUrl(url);
		for (String link : urls) {
			List<BitAutoBrand> bab = baj.getCarInfo(link);
			for (BitAutoBrand b : bab) {
				ycd.insertCarInfo(b);
			}
			System.out.println(link);
		}
	}
}
